package com.xinyun.server.db.dao;

import com.xinyun.server.DB;
import com.xinyun.server.db.ElectricMeter;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by bubusy on 16/6/3.
 */
public class ElectricMeterDao {

    private static ElectricMeterDao instance = new ElectricMeterDao();

    public static ElectricMeterDao getInstance() {
        return instance;
    }

    public ElectricMeter findByMeterId(String meterId) {
        QueryRunner runner = new QueryRunner(DB.dataSource);
        String sql = "select * from z_phaethon_electricmeter where meter_id=?";

        BeanHandler<ElectricMeter> h = new BeanHandler<ElectricMeter>(ElectricMeter.class);

        try {
            ElectricMeter electricMeter = runner.query(sql, h, meterId);
            return electricMeter;

        } catch (SQLException e) {
            e.printStackTrace();
            DbUtils.printStackTrace(e);
            return null;
        }
    }

}
